package tr3dtris.game.models.pieces;

import tr3dtris.game.models.Block;
import tr3dtris.game.models.CellArray;

/**
 * Common S piece builded with four <Block>s.
 * @author Luciano Mammino <loige@hotmail.com>
 * @author Andrea Mangano <kapitan0@hotmail.it>
 * @version 0.1
 * @since 0.1
 */
public class PieceS extends BasicPiece
{
    /**
     * {@inheritDoc}
     */
    private static final int PIECE_ID = 4;

    public PieceS(CellArray parentGrid)
    {
        super(0, 0, parentGrid, PIECE_ID);
    }

    public PieceS(int x, int y, CellArray parentGrid)
    {
        super(x, y, parentGrid, PIECE_ID);
    }

    public PieceS(int x, int y, CellArray parentGrid, int blockType)
    {
        super(x, y, parentGrid, blockType);
    }

    private PieceS(PieceS pieceToCopy) {
        super(pieceToCopy);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected CellArray createBlocks(int type)
    {
        CellArray c = new CellArray(WIDTH, HEIGHT);
        c.addBlockAt(2, 1, new Block(type));
        c.addBlockAt(3, 1, new Block(type));
        c.addBlockAt(1, 2, new Block(type));
        c.addBlockAt(2, 2, new Block(type));
        return c;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected boolean[][] createCwRotationMask()
    {
        boolean[][] b = new boolean[WIDTH][HEIGHT];
        b[1][1] = true;
        b[2][1] = true;
        b[3][1] = true;
        b[1][2] = true;
        b[2][2] = true;
        b[3][2] = true;
        b[3][3] = true;
        return b;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected boolean[][] createCcwRotationMask()
    {
        boolean[][] b = new boolean[WIDTH][HEIGHT];
        b[1][0] = true;
        b[2][0] = true;
        b[3][0] = true;
        b[1][1] = true;
        b[2][1] = true;
        b[3][1] = true;
        b[1][2] = true;
        b[2][2] = true;
        b[2][3] = true;
        return b;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getTypeId()
    {
        return PieceS.PIECE_ID;
    }

    /**
     * {@inheritDoc}
     */
    public AbstractPiece clone()
    {
        return new PieceS(this);
    }
}
